package com.enseirb.bdxmap.activity.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.enseirb.bdxmap.R;

public class DataSourceAdapter extends ArrayAdapter<DataSourceItem>{

	private Context context;
	private DataSourceItem[] values;
	
	public DataSourceAdapter(Context context, List<DataSourceItem> values) {
		super(context, R.layout.data_source_item, values.toArray(new DataSourceItem[values.size()]));
		this.context = context;
		this.values = values.toArray(new DataSourceItem[values.size()]);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View rowView = null;
		
		if(convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = inflater.inflate(R.layout.data_source_item, parent, false);
		}
		
		if(rowView != null) {
			TextView text	= (TextView) rowView.findViewById(R.id.tv_data_source_item);
			ImageView icon	= (ImageView) rowView.findViewById(R.id.iv_data_src);
			
			text.setText(values[position].name);
			icon.setImageDrawable(values[position].drawable);
		}
		
		return rowView;
	}
}
